import math
import sys
import numpy as np
from matplotlib import pyplot as plt

"""
FunctionA(X) = 2 * X + 3
FunctionB(X) = X * X
FunctionAB(X) = 2* X + X * X + 3

Y * Y = 4aX   抛物线
FunctionParabola(X) = 开方(4 * 0.25 * X / 50)
定义域在 [0, 50]  值域在 [0, 1]

使用抛物线函数，修正 A B 的值 再叠加
FunctionTest(X) = FunctionA(X) * FunctionParabola(X) + FunctionB(X) * (1 - FunctionParabola(X))

"""

def FunctionA(X) : 
    return 2* X + 3

def FunctionB(X) : 
    return X * X

def FunctionAB(X):
    return 2* X + X * X + 3

def FunctionParabola(X):
    return math.sqrt(4 * 0.25 * X / 50)


plt.title('Test Function Add')
plt.xlabel("X")
plt.ylabel("Y")

XArray = np.arange(0, 10, 1)
YA =  [FunctionA(X) for X in XArray] 
YB =  [FunctionB(X) for X in XArray] 
YAB = [FunctionAB(X) for X in XArray] 

def TestFunction(X) : 
    Scalar = FunctionParabola(X)
    return FunctionA(X) * Scalar + FunctionB(X) * (1 - Scalar)

YABTest = [TestFunction(X) for X in XArray] 

#YParabola = [FunctionParabola(X) for X in XArray] 

plt.plot(XArray, YA, label="FunctionA")
plt.plot(XArray, YB, label="FunctionB")
plt.plot(XArray, YAB, label="FunctionAB")

plt.plot(XArray, YABTest, label="FunctionTest")

#plt.plot(XArray, YParabola, label="YParabola")


plt.legend()
plt.show()

